package operation;

import book.BookList;

import java.util.Scanner;

public class DeleteBook implements Ioperation{
    public void work(BookList bookList){
        for (int i = 0; i < bookList.getNumber(); i++) {
            System.out.println(bookList.getBook(i));
        }
        System.out.println("请输入你要删除的书：");
        Scanner ip=new Scanner(System.in);
       while(true){
           String name=ip.nextLine();
           for (int j = 0; j < bookList.getNumber()-1 ; j++) {
               if (name.equals(bookList.getBook(j).getName())){
                   int k=0;
                   for (k=j;k<bookList.getNumber()-1;k++){
                       bookList.setBooks(k,bookList.getBook(k+1));
                   }
                   System.out.println("删除成功！！");
                   bookList.setNumber(-1);
                   break;
               }
               else if (bookList.getNumber()-2==j)
                   System.out.println("没有你要删的书");
           }
           System.out.println("请选择：1.继续删书  2.退出");
           int a=ip.nextInt();
           if (a==2)
               break;
       }

    }
}
